<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" scope="page" var="CONTENT_LOCALES_GRID" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" scope="page" var="CONTENT_LOCALES_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" scope="page" var="AVAILABLE_LOCALES_LIST_SIZE_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<atleap:isUserInRole roles="core-contentLocale-changeState" var="canChangeState" />
<atleap:isUserInRole roles="core-contentLocale-setDefault" var="canSetDefault" />
<atleap:isUserInRole roles="core-contentLocale-update" var="canUpdate" />
<atleap:isUserInRole roles="core-contentLocale-view" var="canView" />
<atleap:isUserInRole roles="core-contentLocale-delete" var="canDelete" />

<c:set var="infoCells" value="2" />
<c:set var="constantButtonCells" value="0" />
<c:set var="additionalCells" value="0" />
<c:if test="${canChangeState}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canSetDefault}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canUpdate}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canView}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canDelete}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>

<c:set var="availableLocalesListSize" value="${requestScope[pageScope.AVAILABLE_LOCALES_LIST_SIZE_KEY]}" />
<atleap:content identifier="information" ignore="true" />
<atleap:grid name="${pageScope.CONTENT_LOCALES_GRID}" pageSize="${pageSize}">
    <atleap:messages property="contentLocaleCannotDelete" />
    <atleap:messages property="contentLocaleNotFound" />
    <atleap:messages property="updateFailed" /> 
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="l.identifier" fieldKey="core.contentLocale.form.identifier">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.contentLocale.form.title" />
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
            </tr>
        </thead>
        <tbody>
            <atleap:contextMenu var="menuId">
                <atleap:rowsIterator collection="${requestScope[pageScope.CONTENT_LOCALES_COLLECTION_KEY]}" var="contentLocale" oddClass="oddRow" evenClass="evenRow">
                    <atleap:itemSet>
                        <atleap:rewriteUrl action="core/contentLocale/view" var="defaultUrl">
                            <atleap:param name="identifier" value="${contentLocale.identifier}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="" />
                        <c:set var="tdClass" value="defaultCursorCell" />
                        <c:if test="${canView}">
                            <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            <c:set var="tdClass" value="pointerCursorCell" />
                        </c:if>
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
                            <td class="${tdClass}"><c:out value="${contentLocale.identifier}" escapeXml="true" /></td>
                            <td class="${tdClass}">
                                <atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
                                <c:if test="${empty languageTitle}">
                                    <c:set var="languageTitle" value="${contentLocale.identifier}" />
                                </c:if>
                                ${languageTitle}
                            </td>
                            <c:set var="needButton" value="${availableLocalesListSize> 1 && !contentLocale.defaultInstance}" />
                            <atleap:item enabled="${needButton}" includeInContextMenu="${canSetDefault}" includeInPage="${canSetDefault}">
                                <atleap:message key="core.contentLocale.buttons.setDefault" var="setDefaultMsg" />
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/contentLocale/setDefault" title="${setDefaultMsg}" transaction="true">
                                            <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/notDefault.gif" />" border="0" title="${setDefaultMsg}" alt="${setDefaultMsg}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${setDefaultMsg}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <c:choose>
                                            <c:when test="${!(availableLocalesListSize> 1)}">
                                                <atleap:message key="core.contentLocale.form.singleLocale" var="singleLocaleMsg" />
                                                <atleap:itemLink title="${singleLocaleMsg}">
                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/changeDefaultDisabled.gif" />" border="0" alt="${singleLocaleMsg}" title="${singleLocaleMsg}"  align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${setDefaultMsg}
                                                    </atleap:itemLabel>
                                                </atleap:itemLink>
                                            </c:when>
                                            <c:otherwise>
                                                <atleap:message key="core.contentLocale.buttons.isDefault" var="isDefaultMsg" />
                                                <atleap:itemLink title="${isDefaultMsg}">
                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/default.gif" />" border="0" title="${isDefaultMsg}" alt="${isDefaultMsg}" align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${setDefaultMsg}
                                                    </atleap:itemLabel>
                                                </atleap:itemLink>
                                            </c:otherwise>
                                        </c:choose>
                                    </atleap:itemDisabled>
                                </td>
                            </atleap:item>
                            <c:set var="needButton" value="${!contentLocale.defaultInstance}" />
                            <atleap:item enabled="${needButton}" includeInContextMenu="${canChangeState}" includeInPage="${canChangeState}">
                            <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                <atleap:itemEnabled>
                                    <c:choose>
                                        <c:when test="${contentLocale.active}">
                                            <atleap:message key="core.contentLocale.buttons.makeDisabled" var="makeDisabledMsg" />
                                            <atleap:itemLink action="core/contentLocale/changeState?mode=disabled" title="${makeDisabledMsg}" transaction="true">
                                                <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/active.gif" />" border="0" title="${makeDisabledMsg}" alt="${makeDisabledMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${makeDisabledMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </c:when>
                                        <c:when test="${contentLocale.enabled}">
                                            <atleap:message key="core.contentLocale.buttons.makeActive" var="makeActiveMsg" />
                                            <atleap:itemLink action="core/contentLocale/changeState?mode=active" title="${makeActiveMsg}" transaction="true">
                                                <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/inactive.gif" />" border="0" title="${makeActiveMsg}" alt="${makeActiveMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${makeActiveMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </c:when>
                                        <c:otherwise>
                                            <atleap:message key="core.contentLocale.buttons.makeInactive" var="makeInactiveMsg" />
                                            <atleap:itemLink action="core/contentLocale/changeState?mode=inactive" title="${makeInactiveMsg}" transaction="true">
                                                <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/disabled.gif" />" border="0" title="${makeInactiveMsg}" alt="${makeInactiveMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${makeInactiveMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </c:otherwise>
                                    </c:choose>
                                </atleap:itemEnabled>
                                <atleap:itemDisabled>
                                    <atleap:message key="core.contentLocale.form.changeActivityDisabled" var="changeActivityDisabledMsg" />
                                    <atleap:itemLink title="${changeActivityDisabledMsg}">
                                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/active.gif" />" border="0" alt="${changeActivityDisabledMsg}" title="${changeActivityDisabledMsg}"  align="absmiddle" />
                                        <atleap:itemLabel>
                                            ${changeActivityDisabledMsg}
                                        </atleap:itemLabel>
                                    </atleap:itemLink>
                                </atleap:itemDisabled>
                            </td>
                            </atleap:item>
                            <atleap:item includeInContextMenu="${canUpdate}" includeInPage="${canUpdate}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/contentLocale/callUpdate" title="${callUpdateMsg}">
                                            <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${callUpdateMsg}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                            <atleap:item includeInContextMenu="${canView}" includeInPage="${canView}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:message key="core.commons.buttons.view" var="viewMsg"/>
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/contentLocale/view" title="${viewMsg}">
                                            <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${viewMsg}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                            <atleap:item enabled="${!contentLocale.defaultInstance}" includeInContextMenu="${canDelete}" includeInPage="${canDelete}">
                                <atleap:message key="core.commons.buttons.delete" var="deleteTitle"/>
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/contentLocale/delete" transaction="true" confirmExpression="confirmDelete();" title="${deleteTitle}">
                                            <atleap:param name="identifier" value="${contentLocale.identifier}" />
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/delete.gif" />" border="0" title="${deleteTitle}" alt="${deleteTitle}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${deleteTitle}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <atleap:message key="core.contentLocale.form.deleteDisabled" var="deleteDisabledTitle"/>
                                        <atleap:itemLink title="${deleteDisabledTitle}">
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/deleteDisabled.gif" />" border="0" alt="${deleteDisabledTitle}" title="${deleteDisabledTitle}"  align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${deleteTitle}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemDisabled>
                                </td>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
             <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
             </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <atleap:message key="core.grid.pager.title" />&nbsp;
                        <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                        <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                        <atleap:pagesIterator>
                            <atleap:page>${pageNumber}&nbsp;</atleap:page>
                            <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                        </atleap:pagesIterator>
                        <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                        <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
    <atleap:isUserInRole roles="core-contentLocale-create">
        <atleap:form action="core/contentLocale/callCreate" method="POST" validateOnSubmit="false">
            <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.create" /></atleap:submit>
        </atleap:form>
    </atleap:isUserInRole>
</atleap:grid>
